package cn.shopping.common.exception;

/**
 * 描述:通用异常，一般情况下在各分层都有可以抛出该异常，该异常在被处理
 *
 * @author Zhanggq
 * @date 2019/4/4 10:01
 */
public class CommonException extends RuntimeException {

    public static final long serialVersionUID = -7034897190745766939L;

    public static final Integer DEFAULT_CODE=new Integer(500);


    /**
     * 异常编码
     */
    private Integer code = DEFAULT_CODE;


    /**
     * 异常信息
     */
    private String msg;

    private CommonException(String msg) {
        super(msg);
        this.msg = msg;
    }

    private CommonException(String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
    }

    private CommonException(String msg, Integer code) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    private CommonException(String msg, Integer code, Throwable e) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
    }

    public static CommonException exception(String msg)
    {
        return new CommonException(msg);
    }

    public static CommonException paramException(String msg){
        return new CommonException(msg,CommonErrorCode.PARAM_ERROR_CODE);
    }


    public static CommonException exception(String msg, Throwable e)
    {
        return new CommonException(msg,e);
    }

    public static CommonException exception(String msg, Integer code)
    {
        return new CommonException(msg,code);
    }

    public static CommonException exception(Integer code,String msg)
    {
        return new CommonException(msg,code);
    }

    public static CommonException exception(String msg, Integer code, Throwable e)
    {
        return new CommonException(msg,code,e);
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

}

